exports.userRequired = function(req,res,next){
  if(!req.session || !req.session.user || !req.session.user._id){
    return res.redirect('/login');
  }
  next();
}

exports.authRequired = function(req,res,next){
  if(!req.session.user.activated){
    return res.render('notify/notify',{error: "请先激活你的账号，激活后才可以创建，收藏cheatsheet",user:req.session.user})
  }
  next();
}

exports.authRequired2 = function(req,res,next){
  if(!req.session.user.activated){
    return res.send({status:"unactivated"})
  }
  next();
}

exports.authAdmin = function(req,res,next){
  if(!req.session.user.admin){
    return res.send({status:"not admin"})
  }
  next();
}
